package com.qckj.amz.controller;

import com.qckj.amz.domain.ConfigProductTittle;
import com.qckj.amz.service.IConfigProductTittleService;
import com.qckj.common.annotation.Log;
import com.qckj.common.core.controller.BaseController;
import com.qckj.common.core.domain.AjaxResult;
import com.qckj.common.core.page.TableDataInfo;
import com.qckj.common.enums.BusinessType;
import com.qckj.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 产品标题维护Controller
 *
 * @author luchuan
 * @since 1.0 2022-07-17
 */
@RestController
@RequestMapping("/amz/configProductTittle")
public class ConfigProductTittleController extends BaseController {
    @Autowired
    private IConfigProductTittleService configProductTittleService;

    /**
     * 查询产品标题维护列表
     */
    @PreAuthorize("@ss.hasPermi('amz:configProductTittle:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConfigProductTittle configProductTittle) {
        Page<ConfigProductTittle> page = configProductTittleService.findConfigProductTittlePage(configProductTittle);
        return getDataTable(page);
    }

    /**
     * 导出产品标题维护列表
     */
    @PreAuthorize("@ss.hasPermi('amz:configProductTittle:export')")
    @Log(title = "产品标题维护", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ConfigProductTittle configProductTittle) {
        List<ConfigProductTittle> list = configProductTittleService.findConfigProductTittleList(configProductTittle);
        ExcelUtil<ConfigProductTittle> util = new ExcelUtil<>(ConfigProductTittle.class);
        return util.exportExcel(list, "configProductTittle");
    }

    /**
     * 获取产品标题维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('amz:configProductTittle:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(configProductTittleService.findById(id));
    }

    /**
     * 新增产品标题维护
     */
    @PreAuthorize("@ss.hasPermi('amz:configProductTittle:add')")
    @Log(title = "产品标题维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConfigProductTittle configProductTittle) {
        configProductTittleService.save(configProductTittle);
        return AjaxResult.success();
    }

    /**
     * 修改产品标题维护
     */
    @PreAuthorize("@ss.hasPermi('amz:configProductTittle:edit')")
    @Log(title = "产品标题维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConfigProductTittle configProductTittle) {
        configProductTittleService.save(configProductTittle);
        return AjaxResult.success();
    }

    /**
     * 删除产品标题维护
     */
    @PreAuthorize("@ss.hasPermi('amz:configProductTittle:remove')")
    @Log(title = "产品标题维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        configProductTittleService.deleteByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }

    /**
     * qc语言类型改变时，获取初始化标题数据，qcProductCategory等于0，qcLanguageType等于对应语言的数据
     *
     * qc产品分类，即初始化默认数据，数据库等于0的数据千万别删除，若删除了新增时每个字段都得手动录入
     */
    @PostMapping("/qcLanguageTypeChange")
    public AjaxResult qcLanguageTypeChange(@RequestBody String qcLanguageType) {
        String qcProductCategory = "0";
        ConfigProductTittle configProductTittle = configProductTittleService.qcLanguageTypeChange(qcLanguageType,qcProductCategory);
        return AjaxResult.success(configProductTittle);
    }


}
